package com.liqy.api.util;

import cn.hutool.core.io.IoUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.StringWriter;

/**
 */
public class ServletUtil {
	private ServletUtil() {}
	
	public static JSONObject getRequestJson(HttpServletRequest request) throws IOException {
		StringWriter sw = new StringWriter();
		IoUtil.copy(request.getReader(), sw);
		sw.flush();
		String requestJson = sw.toString();
		JSONObject parseObj = JSONObject.parseObject(requestJson);
		return parseObj;
	}

	public static JSONArray getRequestArray(HttpServletRequest request) throws IOException {
		StringWriter sw = new StringWriter();
		IoUtil.copy(request.getReader(), sw);
		sw.flush();
		String requestJson = sw.toString();
		JSONArray parseObj = JSONObject.parseArray(requestJson);
		return parseObj;
	}

}
